package com.zlsy.secondtime.threadcoreknowledge.sixstates;

/**
 * @author zhouliang
 * @date 2020/5/16 10:55
 * <p>
 * 展示线程的new 、runnable、 Terminated状态
 */
public class NewRunnableTerminated implements Runnable {

    public static void main(String[] args) {
        NewRunnableTerminated r = new NewRunnableTerminated();
        Thread thread = new Thread(r);
        //NEW
        System.out.println("new Thread的时候线程的状态为:" + thread.getState());
        thread.start();
        //RUNNABLE
        System.out.println("刚调用thread.start()线程的状态为:" + thread.getState());
        try {
            Thread.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //RUNNABLE
        System.out.println("调用了thread.start()后，主线程休眠一会，等待子线程执行逻辑，线程的状态为:" + thread.getState());

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        //TERMINATED
        System.out.println("等待子线程的全部执行完之后:" + thread.getState());
    }

    @Override
    public void run() {
        for (int i = 0; i < 1000; i++) {
            System.out.println(i);
        }
    }
}
